package com.kh.rationaldrugreview.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.beans.factory.annotation.Autowired;
import javax.sql.DataSource;

/**
 * Transaction Manager Configuration
 * Resolves conflict between MySQL and Neo4j transaction managers
 */
@Configuration
@EnableTransactionManagement
public class TransactionConfig {
    
    @Autowired
    private DataSource dataSource;
    
    /**
     * Define primary transaction manager for MySQL/MyBatis
     * This will be used for @Transactional annotations without qualifier
     */
    @Bean(name = "transactionManager")
    @Primary
    public DataSourceTransactionManager transactionManager() {
        return new DataSourceTransactionManager(dataSource);
    }
}